import Home from "@/pages/Home";
import Search from "@/pages/Search";
import Register from "@/pages/Register";
import Login from "@/pages/Login";
import Detail from "@/pages/Detail";
import AddCartSuccess from "@/pages/AddCartSuccess";
import ShopCart from "@/pages/ShopCart";
import Pay from "@/pages/Pay";
import Trade from "@/pages/Trade";
import PaySuccess from "@/pages/PaySuccess";
import Center from "@/pages/Center";
import MyOrder from "@/pages/Center/MyOrder";
import GroupOrder from "@/pages/Center/GroupOrder";
import format from "element-ui/src/locale/format";

export default [
    {
        path: '/center',
        component: Center,
        children: [
            {
                path: 'myorder',
                component: MyOrder
            },
            {
                path: 'grouporder',
                component: GroupOrder
            },
            {
                path: '',
                redirect: 'myorder'
            },
        ]
    },
    {
        path: '/paysuccess',
        component: PaySuccess,
        // 路由独享守卫
/*        beforeEnter: (to, from, next) => {
            // 只有从支付页面才能跳转到支付成功页面
            if (from.path === '/pay') {
                next()
            }else {
                alert('只有从支付页面才能跳转到支付成功页面')
                next(false)
            }
        }*/
    },
    {
        path: '/trade',
        component: Trade,
        // 路由独享守卫
        beforeEnter: (to, from, next) => {
            // 只有从购物车界面才能跳转到交易页面
            if(from.path === '/shopcart'){
                next()
            }else{
                alert('只有从购物车界面才能跳转到交易页面')
                next(false)
            }
        }
    },
    {
        path: '/pay',
        component: Pay,
        //只有从交易页面才能跳转到支付页面
        // 路由独享守卫
    /*    beforeEnter: (to, from, next) => {
            // 只有从交易页面才能跳转到支付页面
          if (from.path==='/trade'){
              next()
          }else {
              alert('只有从交易页面才能跳转到支付页面')
          }
        }*/

    },
    {
        path: '/shopcart',
        component: ShopCart
    },
    {
        path: '/detail/:skuId',
        component: Detail
    },
    /*AddCartSuccess*/
    {
        path: '/addCartSuccess',
        component: AddCartSuccess,
        //路由独享守卫
        beforeEnter:(to,from,next)=>{
            //只有携带skuNum和sessionStorage内部的skuInfo数据
            let skuNum=to.query.skuNum
            let skuInfo=sessionStorage.getItem('SESSION_KEY')
            if (skuNum&&skuInfo){
                next()
            }else {
                alert('skuNum&&skuInfo必须携带')
                next(false)
            }
        }

    },
    {
        path: '/home',
        component: Home
    },
    {
        name: 'search',
        path: '/search/:keyword?',
        component: Search,
        //第一种写法 默认是params
        // props:true//props传参第一种写法 默认是params
        //第二种写法 对象
        // props:{username:'zhaoliy'} //映射无关额外的数据为组件的属性 //第三种：函数   可以同时把params和query参数都映射为组件内的属性
        // props(route){
        //   return {keyword:route.params.keyword,keyword1:route.query.keyword1}
        // }

    },
    {
        path: '/register',
        component: Register,
        meta: {
            isHidden: true
        }
    },
    {
        path: '/login',
        component: Login,
        meta: {
            isHidden: true
        }
    },
    {
        path: '/',
        redirect: '/home'
    },
    {
        path: '/communication',
        component: () => import('@/pages/Communication/Communication'),
        children: [
            {
                path: 'event',
                component: () => import('@/pages/Communication/EventTest/EventTest'),
                meta: {
                    isHideFooter: true
                },
            },
            {
                path: 'model',
                component: () => import('@/pages/Communication/ModelTest/ModelTest'),
                meta: {
                    isHideFooter: true
                },
            },
            {
                path: 'sync',
                component: () => import('@/pages/Communication/SyncTest/SyncTest'),
                meta: {
                    isHideFooter: true
                },
            },
            {
                path: 'attrs-listeners',
                component: () => import('@/pages/Communication/AttrsListenersTest/AttrsListenersTest'),
                meta: {
                    isHideFooter: true
                },
            },
            {
                path: 'children-parent',
                component: () => import('@/pages/Communication/ChildrenParentTest/ChildrenParentTest'),
                meta: {
                    isHideFooter: true
                },
            },
            {
                path: 'scope-slot',
                component: () => import('@/pages/Communication/ScopeSlotTest/ScopeSlotTest'),
                meta: {
                    isHideFooter: true
                },
            }
        ],
    },
]